<template>
  <div class="test"></div>
</template>
<script>
 import { createSocket, SocketClose } from "../../../../utils/webSocket";

export default {
  name: "test",
  data() {
    return {
      // path: "ws://82.157.123.54:9010/ajaxchattest",
       path: "ws://121.36.71.77:9023/sendParkingRecord",
      //path: "ws://121.36.71.77:9020",
    };
  },
  created() {},
  mounted() {
     createSocket(this.path);
    // // 添加监听
     this.addEveLis();
  },
  destroyed() {
    // 关闭websocket连接
    // SocketClose();
    // 页面销毁时，移除监听
    window.removeEventListener("onmessageWS", this.handleData);
  },
  methods: {
    // 添加监听事件
    addEveLis() {
      window.addEventListener("onmessageWS", this.handleData);
    },

    // 处理接收的数据
    handleData(info) {
      console.log(info.detail);
    },
  },
};
</script>